<template>
  <el-container class="home-container">
    <el-menu
      router
      ref="menu"
      :collapse="isCollapse"
      :collapse-transition="false"
      :class="['home-menu', isCollapse ? 'collapse-menu' : '']"
    >
      <div class="logo">
        <i class="el-icon-office-building"></i>
        <h1 v-show="!isCollapse">Manager</h1>
      </div>
      <el-menu-item index="/dashboard">
        <!-- <icon-home
            theme="outline"
            size="24"
            fill="#666"
            strokeLinejoin="miter"
          /> -->
        <i class="el-icon-s-home"></i>
        <span slot="title">首页</span>
      </el-menu-item>

      <el-menu-item index="/usermessage">
        <i class="el-icon-user-solid"></i>
        <span slot="title">用户信息管理</span>
      </el-menu-item>

      <el-menu-item index="/user">
        <i class="el-icon-s-custom"></i>
        <span slot="title">用户管理</span>
      </el-menu-item>
      <!-- <el-submenu index="/user">
        <template slot="title">
          <i class="el-icon-s-custom"></i>
          <span>用户管理</span>
        </template>
        <el-menu-item index="/user">
          <span slot="title">用户列表</span>
        </el-menu-item>
        <el-menu-item index="/user/add">
          <span slot="title">添加用户</span>
        </el-menu-item>
        <el-menu-item>
          <span slot="title">修改用户</span>
        </el-menu-item>
      </el-submenu> -->
      <el-submenu index="/post">
        <template slot="title">
          <i class="el-icon-s-order"></i>
          <span>文章管理</span>
        </template>
        <el-menu-item index="/post">
          <span slot="title">文章列表</span>
        </el-menu-item>
        <el-menu-item index="/post/postadd">
          <span slot="title">新增文章</span>
        </el-menu-item>
      </el-submenu>
      <el-menu-item index="/category">
        <i class="el-icon-menu"></i>
        <span slot="title">分类管理</span>
      </el-menu-item>
    </el-menu>
    <el-container>
      <el-header>
        <i
          class="el-icon-s-fold"
          :class="isCollapse ? 'isCollapse' : ''"
          @click="handleCollapse"
        ></i>
        <span class="head">个人博客管理系统</span>
        <el-button type="primary" size="mini" class="exit" @click="handleExit"
          >退出登录</el-button
        >
      </el-header>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      isCollapse: false,
    }
  },
  mounted() {
    // console.log(this.$refs['menu'])
    // console.log(this.$route)
    this.$refs['menu'].activeIndex = this.$route.path
  },
  methods: {
    handleCollapse() {
      // 切换状态
      this.isCollapse = !this.isCollapse
    },
    handleExit() {
      this.$confirm('此操作将退出登录,下次需要重新登录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          localStorage.removeItem('token')
          // 返回登录页面
          this.$router.replace('/login')
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退出',
          })
        })
    },
  },
}
</script>

<style>
.home-container {
  height: 100vh;
}
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
  font-size: 24px;
  color: #333;
}
.el-header i {
  transition: all 0.3s;
}
.el-main {
  background-color: #fff;
}
.logo {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  height: 60px;
  background-color: #409eff;
  font-size: 28px;
  color: #fff;
}
.isCollapse {
  transform: rotate(-180deg);
}
.home-menu {
  width: 200px;
}
.collapse-menu {
  width: 64px;
}
.el-header {
  border-bottom: 2px solid #eee;
}
.el-header .head {
  padding-left: 20px;
  font-family: '华文行楷';
}
</style>
